package gameObjects;

import java.util.HashMap;

import com.jme.input.ChaseCamera;
import com.jme.input.thirdperson.ThirdPersonMouseLook;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.Renderer;
import com.jme.scene.Spatial;
import com.jme.system.DisplaySystem;

public class Cam {
	private static Camera		camera		= null;
	private static ChaseCamera 	chaser		= null;
	private DisplaySystem 		display 	= DisplaySystem.getDisplaySystem();
	private Renderer			renderer  	= display.getRenderer();
	private int					width	  	= display.getWidth();
	private int					height	  	= display.getHeight();
	
	public Cam()
	{
		camera = renderer.createCamera(width, height);
		camera.setFrustumPerspective( 45.0f, (float) display.getWidth() / (float) display.getHeight(), 1, 1000 );
        camera.setParallelProjection( false );
        camera.update();
		
		camera.lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 1, 0));
		camera.normalize();
		camera.setAxes(new Vector3f(0, 0, -1), new Vector3f(0, 1, 0), new Vector3f(1, 0, 0));
		camera.update();
		renderer.setCamera(camera);
	}
	
	public static ChaseCamera buildChaseCamera(Spatial target) {
        Vector3f targetOffset = new Vector3f();
        targetOffset.y=1.0f;
        HashMap<String, Object> props = new HashMap<String, Object>();
        props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "90");
        props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "90");
        props.put(ThirdPersonMouseLook.PROP_MAXASCENT,  "" 
        		                                        + (90 * FastMath.DEG_TO_RAD));
        props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(45 * FastMath.DEG_TO_RAD,
        															  0,
        															 45 * FastMath.DEG_TO_RAD));
        props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
        
        chaser = new ChaseCamera(camera, target, props);
        chaser.setMaxDistance(6);
        chaser.setMinDistance(2);
        chaser.clearActions();
        chaser.setTarget(target);
        chaser.setStayBehindTarget(true);
        chaser.update(0.0f);
        
        return chaser;
    }
	
	public static Camera getCamera()
	{
		return camera; 
	}
	
	public static ChaseCamera getChaser()
	{
		return chaser;
	}
}
